package com.yy.micro.magic.data.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yy.micro.magic.core.model.RuleDescriptor;
import com.yy.micro.magic.data.entity.MagicRuleEntity;
import com.yy.micro.magic.data.model.vo.JpaObjectWithDynamicFieldsVo;

import java.util.List;
import java.util.Map;

public class MagicRuleVo extends JpaObjectWithDynamicFieldsVo {

    private long ruleId;
    private String name;
    private String value;
    private String description;
    private String key;
    private String input;
    private String alias;
    private String formula;
    private String output;
    private String strategy;
    private List<String> params;
    private String format;
    private String fromFormat;
    private int scala;
    private boolean syncParent;
    private boolean dynamic;
    private Map<String,Object> properties;
    private boolean disable;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getInput() {
        return input;
    }

    public void setInput(String input) {
        this.input = input;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getFormula() {
        return formula;
    }

    public void setFormula(String formula) {
        this.formula = formula;
    }

    public String getOutput() {
        return output;
    }

    public void setOutput(String output) {
        this.output = output;
    }

    public String getStrategy() {
        return strategy;
    }

    public void setStrategy(String strategy) {
        this.strategy = strategy;
    }

    public List<String> getParams() {
        return params;
    }

    public void setParams(List<String> params) {
        this.params = params;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public int getScala() {
        return scala;
    }

    public void setScala(int scala) {
        this.scala = scala;
    }

    public long getRuleId() {
        return ruleId;
    }

    public void setRuleId(long ruleId) {
        this.ruleId = ruleId;
    }

    public String getFromFormat() {
        return fromFormat;
    }

    public void setFromFormat(final String fromFormat) {
        this.fromFormat = fromFormat;
    }

    public boolean isSyncParent() {
        return syncParent;
    }

    public void setSyncParent(final boolean syncParent) {
        this.syncParent = syncParent;
    }

    public boolean isDynamic() {
        return dynamic;
    }

    public void setDynamic(final boolean dynamic) {
        this.dynamic = dynamic;
    }

    public Map<String, Object> getProperties() {
        return properties;
    }

    public void setProperties(final Map<String, Object> properties) {
        this.properties = properties;
    }

    public void setDisable(final boolean disable) {
        this.disable = disable;
    }

    public boolean isDisable() {
        return disable;
    }

    @JsonIgnore
    public static MagicRuleVo create(){
        return new MagicRuleVo();
    }

    @JsonIgnore
    public MagicRuleVo from(MagicRuleEntity from){
        super.from(from);
        setAlias(from.getAlias());
        setDescription(from.getDescription());
        setFormat(from.getFormat());
        setFormula(from.getFormula());
        setInput(from.getInput());
        setKey(from.getKey());
        setRuleId(from.getRuleId());
        setName(from.getName());
        setOutput(from.getOutput());
        setParams(from.getParams());
        setScala(from.getScala());
        setStrategy(from.getStrategy());
        setValue(from.getValue());
        setFromFormat(from.getFromFormat());
        setDynamic(from.isDynamic());
        setSyncParent(from.isSyncParent());
        setProperties(from.getProperties());
        setDisable(from.isDisable());
        return this;
    }

    @JsonIgnore
    public MagicRuleEntity to(){
        MagicRuleEntity rule = new MagicRuleEntity();
        super.to(rule);
        rule.setAlias(getAlias());
        rule.setRuleId(getRuleId());
        rule.setFormat(getFormat());
        rule.setFormula(getFormula());
        rule.setInput(getInput());
        rule.setKey(getKey());
        rule.setName(getName());
        rule.setOutput(getOutput());
        rule.setParams(getParams());
        rule.setDescription(getDescription());
        rule.setScala(getScala());
        rule.setStrategy(getStrategy());
        rule.setValue(getValue());
        rule.setProperties(getProperties());
        rule.setFromFormat(getFromFormat());
        rule.setDynamic(isDynamic());
        rule.setSyncParent(isSyncParent());
        rule.setDisable(isDisable());
        return rule;
    }

    @JsonIgnore
    public RuleDescriptor toDomain(){
        RuleDescriptor r = new RuleDescriptor();
        r.setAlias(getAlias());
        r.setDynamic(isDynamic());
        r.setKey(getKey());
        r.setFormat(getFormat());
        r.setFormula(getFormula());
        r.setParas(getParams());
        r.setConfigurations(getProperties());
        r.setInput(getInput());
        r.setScala(getScala());
        r.setStrategy(getStrategy());
        r.setSyncParent(isSyncParent());
        r.setFromFormat(getFromFormat());
        r.setName(getName());
        r.setOutput(getOutput());
        r.setValue(getValue());
        return r;
    }
}
